package com.ruoyi.busi.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.busi.domain.vo.BusiCompanyEletricityVo;
import com.ruoyi.busi.domain.bo.BusiCompanyEletricityBo;
import com.ruoyi.busi.service.IBusiCompanyEletricityService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 电网排放系数Controller
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Validated
@Api(value = "电网排放系数控制器", tags = {"电网排放系数管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/busi/companyEletricity")
public class BusiCompanyEletricityController extends BaseController {

    private final IBusiCompanyEletricityService iBusiCompanyEletricityService;

    /**
     * 查询电网排放系数列表
     */
    @ApiOperation("查询电网排放系数列表")
    @PreAuthorize("@ss.hasPermi('busi:companyEletricity:list')")
    @GetMapping("/list")
    public TableDataInfo<BusiCompanyEletricityVo> list(@Validated(QueryGroup.class) BusiCompanyEletricityBo bo) {
        return iBusiCompanyEletricityService.queryPageList(bo);
    }

    /**
     * 导出电网排放系数列表
     */
    @ApiOperation("导出电网排放系数列表")
    @PreAuthorize("@ss.hasPermi('busi:companyEletricity:export')")
    @Log(title = "电网排放系数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated BusiCompanyEletricityBo bo, HttpServletResponse response) {
        List<BusiCompanyEletricityVo> list = iBusiCompanyEletricityService.queryList(bo);
        ExcelUtil.exportExcel(list, "电网排放系数", BusiCompanyEletricityVo.class, response);
    }

    /**
     * 获取电网排放系数详细信息
     */
    @ApiOperation("获取电网排放系数详细信息")
    @PreAuthorize("@ss.hasPermi('busi:companyEletricity:query')")
    @GetMapping("/{id}")
    public AjaxResult<BusiCompanyEletricityVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return AjaxResult.success(iBusiCompanyEletricityService.queryById(id));
    }

    /**
     * 新增电网排放系数
     */
    @ApiOperation("新增电网排放系数")
    @PreAuthorize("@ss.hasPermi('busi:companyEletricity:add')")
    @Log(title = "电网排放系数", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody BusiCompanyEletricityBo bo) {
        return toAjax(iBusiCompanyEletricityService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改电网排放系数
     */
    @ApiOperation("修改电网排放系数")
    @PreAuthorize("@ss.hasPermi('busi:companyEletricity:edit')")
    @Log(title = "电网排放系数", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody BusiCompanyEletricityBo bo) {
        return toAjax(iBusiCompanyEletricityService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除电网排放系数
     */
    @ApiOperation("删除电网排放系数")
    @PreAuthorize("@ss.hasPermi('busi:companyEletricity:remove')")
    @Log(title = "电网排放系数" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iBusiCompanyEletricityService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
